// 购物车的仓库
import { getShoppingCar, removeGoods, updateGoods } from '../../../Api/index.js'
const shoppingCarAbout = {
  namespaced: true,
  actions: {
    async getShopCar ({ commit }) {
      const result = await getShoppingCar()
      if (result.status === 1) {
        return
      }
      result.data.forEach(element => {
        if (element.isSelect === 1) {
          element.isSelect = true
        } else {
          element.isSelect = false
        }
      })

      commit('GETSHOPCAR', result)
    },
    async removeGoods ({ commit }, id) {
      const result = await removeGoods(id)
      commit('REMOVEGOODS', result)
    },
    async updateGoods ({ commit }, item) {
      const result = await updateGoods(item)
      commit('UPDATEGOODS', result)
    }
  },
  mutations: {
    UPDATEGOODS (state, result) {
      state.updateGoods = result
    },
    GETSHOPCAR (state, val) {
      state.ShoppingCar = val
    },
    REMOVEGOODS (state, val) {
      state.removeGoods = val
    }
  },
  state: {
    ShoppingCar: {},
    removeGoods: {},
    updateGoods: {}
  }
}
export default shoppingCarAbout
